# to manipulate data
import pandas as pd
# for spatial data
import geopandas as gpd
# for plotting
import matplotlib.pyplot as plt
# for network analysis
import networkx as nx
# for street network analysis
import osmnx as ox
# for basemaps
import contextily as ctx
# for interactive webmaps
import folium
!pip install pysal
Collecting pysal Using cached pysal-23.1-py3-none-any.whl (17 kB) Requirement already satisfied: mapclassify>=2.5.0 in /opt/conda/lib/python3.10/site-packages (from pysal) (2.5.0) Collecting spopt>=0.5.0 Using cached spopt-0.5.0-py3-none-any.whl (112 kB) Requirement already satisfied: spreg>=1.3.0 in /opt/conda/lib/python3.10/site-packages (from pysal) (1.3.0) Collecting spvcm>=0.3.0 Using cached spvcm-0.3.0-py3-none-any.whl Requirement already satisfied: giddy>=2.3.3 in /opt/conda/lib/python3.10/site-packages (from pysal) (2.3.3) Collecting momepy>=0.5.4 Using cached momepy-0.5.4-py3-none-any.whl (243 kB) Collecting spglm>=1.0.8 Using cached spglm-1.0.8-py3-none-any.whl Requirement already satisfied: splot>=1.1.5.post1 in /opt/conda/lib/python3.10/site-packages (from pysal) (1.1.5.post1) Collecting mgwr>=2.1.2 Using cached mgwr-2.1.2-py3-none-any.whl Collecting spint>=1.0.7 Using cached spint-1.0.7-py3-none-any.whl Collecting segregation>=2.3.1 Using cached segregation-2.3.1-py3-none-any.whl (147 kB) Collecting tobler>=0.8.2 Using cached tobler-0.9.0-py3-none-any.whl (22 kB) Requirement already satisfied: libpysal>=4.7.0 in /opt/conda/lib/python3.10/site-packages (from pysal) (4.7.0) Collecting pointpats>=2.2.0 Using cached pointpats-2.3.0-py3-none-any.whl (59 kB) Requirement already satisfied: esda>=2.4.1 in /opt/conda/lib/python3.10/site-packages (from pysal) (2.4.3) Collecting inequality>=1.0.0 Using cached inequality-1.0.0-py3-none-any.whl Collecting access>=1.1.8 Using cached access-1.1.8-py3-none-any.whl (21 kB) Collecting spaghetti>=1.7.2 Using cached spaghetti-1.7.2-py3-none-any.whl (50 kB) Requirement already satisfied: requests>=2 in /opt/conda/lib/python3.10/site-packages (from access>=1.1.8->pysal) (2.28.1) Requirement already satisfied: pandas>=0.23.4 in /opt/conda/lib/python3.10/site-packages (from access>=1.1.8->pysal) (1.5.2) Requirement already satisfied: numpy>=1.3 in /opt/conda/lib/python3.10/site-packages (from access>=1.1.8->pysal) (1.23.5) Requirement already satisfied: geopandas in /opt/conda/lib/python3.10/site-packages (from access>=1.1.8->pysal) (0.12.2) Requirement already satisfied: scikit-learn in /opt/conda/lib/python3.10/site-packages (from esda>=2.4.1->pysal) (1.2.0) Requirement already satisfied: scipy>=0.11 in /opt/conda/lib/python3.10/site-packages (from esda>=2.4.1->pysal) (1.10.0) Requirement already satisfied: quantecon>=0.4.7 in /opt/conda/lib/python3.10/site-packages (from giddy>=2.3.3->pysal) (0.6.0) Requirement already satisfied: packaging in /opt/conda/lib/python3.10/site-packages (from libpysal>=4.7.0->pysal) (22.0) Requirement already satisfied: beautifulsoup4 in /opt/conda/lib/python3.10/site-packages (from libpysal>=4.7.0->pysal) (4.11.1) Requirement already satisfied: platformdirs in /opt/conda/lib/python3.10/site-packages (from libpysal>=4.7.0->pysal) (2.6.2) Requirement already satisfied: jinja2 in /opt/conda/lib/python3.10/site-packages (from libpysal>=4.7.0->pysal) (3.1.2) Requirement already satisfied: networkx in /opt/conda/lib/python3.10/site-packages (from mapclassify>=2.5.0->pysal) (3.0) Collecting pygeos Using cached pygeos-0.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB) Requirement already satisfied: tqdm>=4.27.0 in /opt/conda/lib/python3.10/site-packages (from momepy>=0.5.4->pysal) (4.64.1) Requirement already satisfied: matplotlib in /opt/conda/lib/python3.10/site-packages (from pointpats>=2.2.0->pysal) (3.6.2) Requirement already satisfied: pyproj>=3 in /opt/conda/lib/python3.10/site-packages (from segregation>=2.3.1->pysal) (3.4.1) Collecting quilt3 Using cached quilt3-5.1.1-py3-none-any.whl (79 kB) Requirement already satisfied: seaborn in /opt/conda/lib/python3.10/site-packages (from segregation>=2.3.1->pysal) (0.12.2) Collecting rvlib>=0.0.5 Using cached rvlib-0.0.6-cp310-cp310-linux_x86_64.whl Requirement already satisfied: pip in /opt/conda/lib/python3.10/site-packages (from segregation>=2.3.1->pysal) (22.3.1) Collecting deprecation Using cached deprecation-2.1.0-py2.py3-none-any.whl (11 kB) Requirement already satisfied: joblib in /opt/conda/lib/python3.10/site-packages (from segregation>=2.3.1->pysal) (1.2.0) Requirement already satisfied: numba in /opt/conda/lib/python3.10/site-packages (from segregation>=2.3.1->pysal) (0.56.4) Requirement already satisfied: rtree in /opt/conda/lib/python3.10/site-packages (from spaghetti>=1.7.2->pysal) (1.0.1) Collecting pulp Using cached PuLP-2.7.0-py3-none-any.whl (14.3 MB) Requirement already satisfied: rasterio in /opt/conda/lib/python3.10/site-packages (from tobler>=0.8.2->pysal) (1.3.4) Requirement already satisfied: statsmodels in /opt/conda/lib/python3.10/site-packages (from tobler>=0.8.2->pysal) (0.13.5) Collecting rasterstats Using cached rasterstats-0.18.0-py3-none-any.whl (17 kB) Requirement already satisfied: fiona>=1.8 in /opt/conda/lib/python3.10/site-packages (from geopandas->access>=1.1.8->pysal) (1.8.22) Requirement already satisfied: shapely>=1.7 in /opt/conda/lib/python3.10/site-packages (from geopandas->access>=1.1.8->pysal) (2.0.0) Requirement already satisfied: python-dateutil>=2.8.1 in /opt/conda/lib/python3.10/site-packages (from pandas>=0.23.4->access>=1.1.8->pysal) (2.8.2) Requirement already satisfied: pytz>=2020.1 in /opt/conda/lib/python3.10/site-packages (from pandas>=0.23.4->access>=1.1.8->pysal) (2022.7) Requirement already satisfied: certifi in /opt/conda/lib/python3.10/site-packages (from pyproj>=3->segregation>=2.3.1->pysal) (2022.12.7) Requirement already satisfied: sympy in /opt/conda/lib/python3.10/site-packages (from quantecon>=0.4.7->giddy>=2.3.3->pysal) (1.11.1) Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.10/site-packages (from requests>=2->access>=1.1.8->pysal) (3.4) Requirement already satisfied: charset-normalizer<3,>=2 in /opt/conda/lib/python3.10/site-packages (from requests>=2->access>=1.1.8->pysal) (2.1.1) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/lib/python3.10/site-packages (from requests>=2->access>=1.1.8->pysal) (1.26.13) Requirement already satisfied: cffi>=1.0.0 in /opt/conda/lib/python3.10/site-packages (from rvlib>=0.0.5->segregation>=2.3.1->pysal) (1.15.1) Requirement already satisfied: PyYAML in /opt/conda/lib/python3.10/site-packages (from rvlib>=0.0.5->segregation>=2.3.1->pysal) (6.0) Requirement already satisfied: llvmlite<0.40,>=0.39.0dev0 in /opt/conda/lib/python3.10/site-packages (from numba->segregation>=2.3.1->pysal) (0.39.1) Requirement already satisfied: setuptools in /opt/conda/lib/python3.10/site-packages (from numba->segregation>=2.3.1->pysal) (65.6.3) Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/lib/python3.10/site-packages (from scikit-learn->esda>=2.4.1->pysal) (3.1.0) Requirement already satisfied: soupsieve>1.2 in /opt/conda/lib/python3.10/site-packages (from beautifulsoup4->libpysal>=4.7.0->pysal) (2.3.2.post1) Requirement already satisfied: MarkupSafe>=2.0 in /opt/conda/lib/python3.10/site-packages (from jinja2->libpysal>=4.7.0->pysal) (2.1.1) Requirement already satisfied: pillow>=6.2.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pointpats>=2.2.0->pysal) (9.4.0) Requirement already satisfied: pyparsing>=2.2.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pointpats>=2.2.0->pysal) (3.0.9) Requirement already satisfied: fonttools>=4.22.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pointpats>=2.2.0->pysal) (4.38.0) Requirement already satisfied: contourpy>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pointpats>=2.2.0->pysal) (1.0.6) Requirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pointpats>=2.2.0->pysal) (0.11.0) Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib->pointpats>=2.2.0->pysal) (1.4.4) Requirement already satisfied: jsonschema<5,>=3 in /opt/conda/lib/python3.10/site-packages (from quilt3->segregation>=2.3.1->pysal) (4.17.3) Collecting aws-requests-auth>=0.4.2 Using cached aws_requests_auth-0.4.3-py2.py3-none-any.whl (6.8 kB) Collecting boto3>=1.10.0 Using cached boto3-1.26.94-py3-none-any.whl (135 kB) Collecting jsonlines==1.2.0 Using cached jsonlines-1.2.0-py2.py3-none-any.whl (7.6 kB) Collecting requests-futures==1.0.0 Using cached requests_futures-1.0.0-py2.py3-none-any.whl (7.4 kB) Requirement already satisfied: tenacity>=5.1.1 in /opt/conda/lib/python3.10/site-packages (from quilt3->segregation>=2.3.1->pysal) (8.1.0) Requirement already satisfied: six in /opt/conda/lib/python3.10/site-packages (from jsonlines==1.2.0->quilt3->segregation>=2.3.1->pysal) (1.16.0) Requirement already satisfied: snuggs>=1.4.1 in /opt/conda/lib/python3.10/site-packages (from rasterio->tobler>=0.8.2->pysal) (1.4.7) Requirement already satisfied: click>=4.0 in /opt/conda/lib/python3.10/site-packages (from rasterio->tobler>=0.8.2->pysal) (8.1.3) Requirement already satisfied: attrs in /opt/conda/lib/python3.10/site-packages (from rasterio->tobler>=0.8.2->pysal) (22.2.0) Requirement already satisfied: click-plugins in /opt/conda/lib/python3.10/site-packages (from rasterio->tobler>=0.8.2->pysal) (1.1.1) Requirement already satisfied: cligj>=0.5 in /opt/conda/lib/python3.10/site-packages (from rasterio->tobler>=0.8.2->pysal) (0.7.2) Requirement already satisfied: affine in /opt/conda/lib/python3.10/site-packages (from rasterio->tobler>=0.8.2->pysal) (2.3.1) Collecting simplejson Using cached simplejson-3.18.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (137 kB) Requirement already satisfied: patsy>=0.5.2 in /opt/conda/lib/python3.10/site-packages (from statsmodels->tobler>=0.8.2->pysal) (0.5.3) Collecting botocore<1.30.0,>=1.29.94 Using cached botocore-1.29.94-py3-none-any.whl (10.5 MB) Collecting jmespath<2.0.0,>=0.7.1 Using cached jmespath-1.0.1-py3-none-any.whl (20 kB) Collecting s3transfer<0.7.0,>=0.6.0 Using cached s3transfer-0.6.0-py3-none-any.whl (79 kB) Requirement already satisfied: pycparser in /opt/conda/lib/python3.10/site-packages (from cffi>=1.0.0->rvlib>=0.0.5->segregation>=2.3.1->pysal) (2.21) Requirement already satisfied: munch in /opt/conda/lib/python3.10/site-packages (from fiona>=1.8->geopandas->access>=1.1.8->pysal) (2.5.0) Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /opt/conda/lib/python3.10/site-packages (from jsonschema<5,>=3->quilt3->segregation>=2.3.1->pysal) (0.19.3) Requirement already satisfied: mpmath>=0.19 in /opt/conda/lib/python3.10/site-packages (from sympy->quantecon>=0.4.7->giddy>=2.3.3->pysal) (1.2.1) Installing collected packages: pulp, simplejson, pygeos, jsonlines, jmespath, deprecation, rvlib, requests-futures, inequality, botocore, aws-requests-auth, s3transfer, rasterstats, tobler, pointpats, momepy, boto3, access, spvcm, spglm, spaghetti, quilt3, spopt, spint, segregation, mgwr, pysal Successfully installed access-1.1.8 aws-requests-auth-0.4.3 boto3-1.26.94 botocore-1.29.94 deprecation-2.1.0 inequality-1.0.0 jmespath-1.0.1 jsonlines-1.2.0 mgwr-2.1.2 momepy-0.5.4 pointpats-2.3.0 pulp-2.7.0 pygeos-0.14 pysal-23.1 quilt3-5.1.1 rasterstats-0.18.0 requests-futures-1.0.0 rvlib-0.0.6 s3transfer-0.6.0 segregation-2.3.1 simplejson-3.18.4 spaghetti-1.7.2 spglm-1.0.8 spint-1.0.7 spopt-0.5.0 spvcm-0.3.0 tobler-0.9.0
# Importing pysal to reclassify data
import pysal as ps
import mapclassify
n_classes = 5
# Importing data
df=gpd.read_file('Los_Angeles_County_CVA_Social_Vulnerability_Index.geojson')
These are the variables that the CVA dataset considers for social vulnerability:
Children Older_Adults Older_Adults_Living_Alone Limited_English No_High_School_Diploma Female Female_Householder Asthma Cardiovascular_Disease Disability No_Health_Insurance Living_in_Group_Quarters Mobile_Homes Rent_Burden Renters Median_Income Poverty Households_Without_Vehicle_Acce Transit_Access Outdoor_Workers Unemployed Foreign_Born Library_Access No_Internet_Subscription Voter_Turnout_Rate Hispanic_Latinx White Black Native_Tribal Asian NHOPI Other_Race Two_or_More_Races SoVI_Score SoVI_Thirds
I want to focus on the variables that seem most related to extreme heat vulnerability, esp related to cooling centers and transit. These are the variables I will use in my custom index:
# Trimming data
df_trimmed=df[['Census_Tract','Poverty', 'Households_Without_Vehicle_Acce', 'Transit_Access', 'Outdoor_Workers', 'Library_Access','geometry']]
classifier=mapclassify.NaturalBreaks.make(k=5)
df_trimmed['poverty_classes']=df_trimmed[["Poverty"]].apply(classifier)
df_trimmed
/opt/conda/lib/python3.10/site-packages/geopandas/geodataframe.py:1443: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy super().__setitem__(key, value)
| Census_Tract | Poverty | Households_Without_Vehicle_Acce | Transit_Access | Outdoor_Workers | Library_Access | geometry | poverty_classes | |
|---|---|---|---|---|---|---|---|---|
| 0 | Census Tract 5709.02 | 1.5 | 3.8 | 0.0 | 5.6 | 0.8 | POLYGON ((-118.12509 33.86032, -118.12287 33.8... | 0 |
| 1 | Census Tract 5715.02 | 10.0 | 9.0 | 98.3 | 2.5 | 1.2 | POLYGON ((-118.19274 33.84376, -118.18975 33.8... | 0 |
| 2 | Census Tract 9106.05 | 17.1 | 3.3 | 0.0 | 11.6 | 2.9 | POLYGON ((-118.07616 34.57281, -118.06728 34.5... | 1 |
| 3 | Census Tract 9107.12 | 7.0 | 0.9 | 0.0 | 3.6 | 4.2 | POLYGON ((-118.05857 34.55809, -118.05847 34.5... | 0 |
| 4 | Census Tract 9107.15 | 11.3 | 8.9 | 0.0 | 4.6 | 3.1 | POLYGON ((-118.08506 34.55654, -118.08485 34.5... | 1 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2322 | Census Tract 6010.02 | 19.6 | 12.4 | 100.0 | 7.1 | 0.7 | POLYGON ((-118.35263 33.95271, -118.35208 33.9... | 2 |
| 2323 | Census Tract 9005.01 | 28.7 | 4.9 | 0.0 | 7.3 | 1.5 | POLYGON ((-118.13480 34.68936, -118.12968 34.6... | 2 |
| 2324 | Census Tract 9200.29 | 5.4 | 3.7 | 0.0 | 2.7 | 1.6 | POLYGON ((-118.50373 34.42607, -118.50050 34.4... | 0 |
| 2325 | Census Tract 5420 | 13.3 | 8.7 | 88.0 | 9.3 | 0.7 | POLYGON ((-118.20731 33.90754, -118.20641 33.9... | 1 |
| 2326 | Census Tract 1244 | 12.9 | 6.4 | 0.0 | 2.3 | 1.4 | POLYGON ((-118.41379 34.17940, -118.41160 34.1... | 1 |
2327 rows × 8 columns
df_trimmed['vehicleaccess_classes']=df_trimmed[["Households_Without_Vehicle_Acce"]].apply(classifier)
df_trimmed
/opt/conda/lib/python3.10/site-packages/geopandas/geodataframe.py:1443: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy super().__setitem__(key, value)
| Census_Tract | Poverty | Households_Without_Vehicle_Acce | Transit_Access | Outdoor_Workers | Library_Access | geometry | poverty_classes | vehicleaccess_classes | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | Census Tract 5709.02 | 1.5 | 3.8 | 0.0 | 5.6 | 0.8 | POLYGON ((-118.12509 33.86032, -118.12287 33.8... | 0 | 0 |
| 1 | Census Tract 5715.02 | 10.0 | 9.0 | 98.3 | 2.5 | 1.2 | POLYGON ((-118.19274 33.84376, -118.18975 33.8... | 0 | 1 |
| 2 | Census Tract 9106.05 | 17.1 | 3.3 | 0.0 | 11.6 | 2.9 | POLYGON ((-118.07616 34.57281, -118.06728 34.5... | 1 | 0 |
| 3 | Census Tract 9107.12 | 7.0 | 0.9 | 0.0 | 3.6 | 4.2 | POLYGON ((-118.05857 34.55809, -118.05847 34.5... | 0 | 0 |
| 4 | Census Tract 9107.15 | 11.3 | 8.9 | 0.0 | 4.6 | 3.1 | POLYGON ((-118.08506 34.55654, -118.08485 34.5... | 1 | 1 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2322 | Census Tract 6010.02 | 19.6 | 12.4 | 100.0 | 7.1 | 0.7 | POLYGON ((-118.35263 33.95271, -118.35208 33.9... | 2 | 2 |
| 2323 | Census Tract 9005.01 | 28.7 | 4.9 | 0.0 | 7.3 | 1.5 | POLYGON ((-118.13480 34.68936, -118.12968 34.6... | 2 | 0 |
| 2324 | Census Tract 9200.29 | 5.4 | 3.7 | 0.0 | 2.7 | 1.6 | POLYGON ((-118.50373 34.42607, -118.50050 34.4... | 0 | 0 |
| 2325 | Census Tract 5420 | 13.3 | 8.7 | 88.0 | 9.3 | 0.7 | POLYGON ((-118.20731 33.90754, -118.20641 33.9... | 1 | 1 |
| 2326 | Census Tract 1244 | 12.9 | 6.4 | 0.0 | 2.3 | 1.4 | POLYGON ((-118.41379 34.17940, -118.41160 34.1... | 1 | 1 |
2327 rows × 9 columns
df_trimmed['transitaccess_classes']=df_trimmed[["Transit_Access"]].apply(classifier)
df_trimmed
/opt/conda/lib/python3.10/site-packages/geopandas/geodataframe.py:1443: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy super().__setitem__(key, value)
| Census_Tract | Poverty | Households_Without_Vehicle_Acce | Transit_Access | Outdoor_Workers | Library_Access | geometry | poverty_classes | vehicleaccess_classes | transitaccess_classes | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Census Tract 5709.02 | 1.5 | 3.8 | 0.0 | 5.6 | 0.8 | POLYGON ((-118.12509 33.86032, -118.12287 33.8... | 0 | 0 | 0 |
| 1 | Census Tract 5715.02 | 10.0 | 9.0 | 98.3 | 2.5 | 1.2 | POLYGON ((-118.19274 33.84376, -118.18975 33.8... | 0 | 1 | 4 |
| 2 | Census Tract 9106.05 | 17.1 | 3.3 | 0.0 | 11.6 | 2.9 | POLYGON ((-118.07616 34.57281, -118.06728 34.5... | 1 | 0 | 0 |
| 3 | Census Tract 9107.12 | 7.0 | 0.9 | 0.0 | 3.6 | 4.2 | POLYGON ((-118.05857 34.55809, -118.05847 34.5... | 0 | 0 | 0 |
| 4 | Census Tract 9107.15 | 11.3 | 8.9 | 0.0 | 4.6 | 3.1 | POLYGON ((-118.08506 34.55654, -118.08485 34.5... | 1 | 1 | 0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2322 | Census Tract 6010.02 | 19.6 | 12.4 | 100.0 | 7.1 | 0.7 | POLYGON ((-118.35263 33.95271, -118.35208 33.9... | 2 | 2 | 4 |
| 2323 | Census Tract 9005.01 | 28.7 | 4.9 | 0.0 | 7.3 | 1.5 | POLYGON ((-118.13480 34.68936, -118.12968 34.6... | 2 | 0 | 0 |
| 2324 | Census Tract 9200.29 | 5.4 | 3.7 | 0.0 | 2.7 | 1.6 | POLYGON ((-118.50373 34.42607, -118.50050 34.4... | 0 | 0 | 0 |
| 2325 | Census Tract 5420 | 13.3 | 8.7 | 88.0 | 9.3 | 0.7 | POLYGON ((-118.20731 33.90754, -118.20641 33.9... | 1 | 1 | 3 |
| 2326 | Census Tract 1244 | 12.9 | 6.4 | 0.0 | 2.3 | 1.4 | POLYGON ((-118.41379 34.17940, -118.41160 34.1... | 1 | 1 | 0 |
2327 rows × 10 columns
df_trimmed['outdoorwork_classes']=df_trimmed[["Outdoor_Workers"]].apply(classifier)
df_trimmed
/opt/conda/lib/python3.10/site-packages/geopandas/geodataframe.py:1443: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy super().__setitem__(key, value)
| Census_Tract | Poverty | Households_Without_Vehicle_Acce | Transit_Access | Outdoor_Workers | Library_Access | geometry | poverty_classes | vehicleaccess_classes | transitaccess_classes | outdoorwork_classes | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Census Tract 5709.02 | 1.5 | 3.8 | 0.0 | 5.6 | 0.8 | POLYGON ((-118.12509 33.86032, -118.12287 33.8... | 0 | 0 | 0 | 1 |
| 1 | Census Tract 5715.02 | 10.0 | 9.0 | 98.3 | 2.5 | 1.2 | POLYGON ((-118.19274 33.84376, -118.18975 33.8... | 0 | 1 | 4 | 0 |
| 2 | Census Tract 9106.05 | 17.1 | 3.3 | 0.0 | 11.6 | 2.9 | POLYGON ((-118.07616 34.57281, -118.06728 34.5... | 1 | 0 | 0 | 3 |
| 3 | Census Tract 9107.12 | 7.0 | 0.9 | 0.0 | 3.6 | 4.2 | POLYGON ((-118.05857 34.55809, -118.05847 34.5... | 0 | 0 | 0 | 1 |
| 4 | Census Tract 9107.15 | 11.3 | 8.9 | 0.0 | 4.6 | 3.1 | POLYGON ((-118.08506 34.55654, -118.08485 34.5... | 1 | 1 | 0 | 1 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2322 | Census Tract 6010.02 | 19.6 | 12.4 | 100.0 | 7.1 | 0.7 | POLYGON ((-118.35263 33.95271, -118.35208 33.9... | 2 | 2 | 4 | 2 |
| 2323 | Census Tract 9005.01 | 28.7 | 4.9 | 0.0 | 7.3 | 1.5 | POLYGON ((-118.13480 34.68936, -118.12968 34.6... | 2 | 0 | 0 | 2 |
| 2324 | Census Tract 9200.29 | 5.4 | 3.7 | 0.0 | 2.7 | 1.6 | POLYGON ((-118.50373 34.42607, -118.50050 34.4... | 0 | 0 | 0 | 0 |
| 2325 | Census Tract 5420 | 13.3 | 8.7 | 88.0 | 9.3 | 0.7 | POLYGON ((-118.20731 33.90754, -118.20641 33.9... | 1 | 1 | 3 | 2 |
| 2326 | Census Tract 1244 | 12.9 | 6.4 | 0.0 | 2.3 | 1.4 | POLYGON ((-118.41379 34.17940, -118.41160 34.1... | 1 | 1 | 0 | 0 |
2327 rows × 11 columns
df_trimmed['libraryaccess_classes']=df_trimmed[["Library_Access"]].apply(classifier)
df_trimmed
/opt/conda/lib/python3.10/site-packages/geopandas/geodataframe.py:1443: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy super().__setitem__(key, value)
| Census_Tract | Poverty | Households_Without_Vehicle_Acce | Transit_Access | Outdoor_Workers | Library_Access | geometry | poverty_classes | vehicleaccess_classes | transitaccess_classes | outdoorwork_classes | libraryaccess_classes | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Census Tract 5709.02 | 1.5 | 3.8 | 0.0 | 5.6 | 0.8 | POLYGON ((-118.12509 33.86032, -118.12287 33.8... | 0 | 0 | 0 | 1 | 0 |
| 1 | Census Tract 5715.02 | 10.0 | 9.0 | 98.3 | 2.5 | 1.2 | POLYGON ((-118.19274 33.84376, -118.18975 33.8... | 0 | 1 | 4 | 0 | 1 |
| 2 | Census Tract 9106.05 | 17.1 | 3.3 | 0.0 | 11.6 | 2.9 | POLYGON ((-118.07616 34.57281, -118.06728 34.5... | 1 | 0 | 0 | 3 | 2 |
| 3 | Census Tract 9107.12 | 7.0 | 0.9 | 0.0 | 3.6 | 4.2 | POLYGON ((-118.05857 34.55809, -118.05847 34.5... | 0 | 0 | 0 | 1 | 3 |
| 4 | Census Tract 9107.15 | 11.3 | 8.9 | 0.0 | 4.6 | 3.1 | POLYGON ((-118.08506 34.55654, -118.08485 34.5... | 1 | 1 | 0 | 1 | 2 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2322 | Census Tract 6010.02 | 19.6 | 12.4 | 100.0 | 7.1 | 0.7 | POLYGON ((-118.35263 33.95271, -118.35208 33.9... | 2 | 2 | 4 | 2 | 0 |
| 2323 | Census Tract 9005.01 | 28.7 | 4.9 | 0.0 | 7.3 | 1.5 | POLYGON ((-118.13480 34.68936, -118.12968 34.6... | 2 | 0 | 0 | 2 | 1 |
| 2324 | Census Tract 9200.29 | 5.4 | 3.7 | 0.0 | 2.7 | 1.6 | POLYGON ((-118.50373 34.42607, -118.50050 34.4... | 0 | 0 | 0 | 0 | 1 |
| 2325 | Census Tract 5420 | 13.3 | 8.7 | 88.0 | 9.3 | 0.7 | POLYGON ((-118.20731 33.90754, -118.20641 33.9... | 1 | 1 | 3 | 2 | 0 |
| 2326 | Census Tract 1244 | 12.9 | 6.4 | 0.0 | 2.3 | 1.4 | POLYGON ((-118.41379 34.17940, -118.41160 34.1... | 1 | 1 | 0 | 0 | 1 |
2327 rows × 12 columns
df_trimmed['Heat_Score']=df_trimmed['poverty_classes']+df_trimmed['vehicleaccess_classes']+df_trimmed['transitaccess_classes']+df_trimmed['outdoorwork_classes']+df_trimmed['libraryaccess_classes']
df_trimmed
/opt/conda/lib/python3.10/site-packages/geopandas/geodataframe.py:1443: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy super().__setitem__(key, value)
| Census_Tract | Poverty | Households_Without_Vehicle_Acce | Transit_Access | Outdoor_Workers | Library_Access | geometry | poverty_classes | vehicleaccess_classes | transitaccess_classes | outdoorwork_classes | libraryaccess_classes | Heat_Score | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Census Tract 5709.02 | 1.5 | 3.8 | 0.0 | 5.6 | 0.8 | POLYGON ((-118.12509 33.86032, -118.12287 33.8... | 0 | 0 | 0 | 1 | 0 | 1 |
| 1 | Census Tract 5715.02 | 10.0 | 9.0 | 98.3 | 2.5 | 1.2 | POLYGON ((-118.19274 33.84376, -118.18975 33.8... | 0 | 1 | 4 | 0 | 1 | 6 |
| 2 | Census Tract 9106.05 | 17.1 | 3.3 | 0.0 | 11.6 | 2.9 | POLYGON ((-118.07616 34.57281, -118.06728 34.5... | 1 | 0 | 0 | 3 | 2 | 6 |
| 3 | Census Tract 9107.12 | 7.0 | 0.9 | 0.0 | 3.6 | 4.2 | POLYGON ((-118.05857 34.55809, -118.05847 34.5... | 0 | 0 | 0 | 1 | 3 | 4 |
| 4 | Census Tract 9107.15 | 11.3 | 8.9 | 0.0 | 4.6 | 3.1 | POLYGON ((-118.08506 34.55654, -118.08485 34.5... | 1 | 1 | 0 | 1 | 2 | 5 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2322 | Census Tract 6010.02 | 19.6 | 12.4 | 100.0 | 7.1 | 0.7 | POLYGON ((-118.35263 33.95271, -118.35208 33.9... | 2 | 2 | 4 | 2 | 0 | 10 |
| 2323 | Census Tract 9005.01 | 28.7 | 4.9 | 0.0 | 7.3 | 1.5 | POLYGON ((-118.13480 34.68936, -118.12968 34.6... | 2 | 0 | 0 | 2 | 1 | 5 |
| 2324 | Census Tract 9200.29 | 5.4 | 3.7 | 0.0 | 2.7 | 1.6 | POLYGON ((-118.50373 34.42607, -118.50050 34.4... | 0 | 0 | 0 | 0 | 1 | 1 |
| 2325 | Census Tract 5420 | 13.3 | 8.7 | 88.0 | 9.3 | 0.7 | POLYGON ((-118.20731 33.90754, -118.20641 33.9... | 1 | 1 | 3 | 2 | 0 | 7 |
| 2326 | Census Tract 1244 | 12.9 | 6.4 | 0.0 | 2.3 | 1.4 | POLYGON ((-118.41379 34.17940, -118.41160 34.1... | 1 | 1 | 0 | 0 | 1 | 3 |
2327 rows × 13 columns
# Mapping
m=folium.Map(location=[34.2,-118.2],
zoom_start=9,
tiles='CartoDB positron',
attribute='CartoDB')
style1 = {'fillOpacity': '0.0',
'stroke': True,
'weight': '3'}
folium. GeoJson ('Los_Angeles_County_CVA_Social_Vulnerability_Index.geojson',
highlight_function=None,
style_function=lambda x:style1,
name="City",
overlay=True,
control=True,
show=False,
smooth_factor=None,
tooltip=None,
embed=True,
popup=None,
zoom_on_click=True,
marker=None
).add_to (m)
<folium.features.GeoJson at 0x7fe35ff94940>
folium.Choropleth(
geo_data=df_trimmed,
data=df_trimmed,
key_on='feature.properties.Census_Tract',
columns=['Census_Tract', 'Heat_Score'],
fill_color='YlOrRd',
line_weight=0.8,
fill_opacity=1.0,
line_opacity=0.4,
legend_name='Heat Vulnerability Index',
name='Heat Vulnerability Index',
reset=True,
).add_to (m)
folium.LayerControl().add_to (m)
m
#Make this Notebook Trusted (File>Trust Notebook)
jupyter trust /up221-amanda/Week07/week 10 assignment.ipynb
Cell In[23], line 2 jupyter trust /up221-amanda/Week07/week 10 assignment.ipynb ^ SyntaxError: invalid syntax